#登录业务

import allure,time
#导入该业务相关的页面类
from page.page_index import PageIndex #首页
from page.page_login import PageLogin #登录页
from page.page_user import PageUser #个人中心页面

class ServiceLogin(object):
    def __init__(self,driver):
        #初始化driver
        self.driver=driver
        #初始化该业务相关的页面类
        self.page_index=PageIndex(self.driver)
        self.page_login=PageLogin(self.driver)
        self.page_user=PageUser(self.driver)


    def service_login_001(self,data):
        #业务步骤
        #UI1的业务步骤
        allure.attach("","打开首页")
        self.page_index.openUrl()
        allure.attach("", "点击“首页”的登录按钮")
        self.page_index.click_Login()

        #UI2的业务步骤
        allure.attach("", f'输入账号:{data["zanhao"]}')
        self.page_login.input_zanhao(data["zanhao"])
        allure.attach("", f'输入账号:{data["pwd"]}')
        self.page_login.input_pwd(data["pwd"])

        allure.attach("", "点击登录页面的登录按钮")
        self.page_login.click_login()
        time.sleep(2)

        #截图
        imageName=self.page_user.savePng3("登录业务",data["key"])
        allure.attach(open('./screen/' + imageName + '.png', 'rb').read(), "本次截图", allure.attachment_type.PNG)

        #UI3的业务步骤
        siji=self.page_user.getH2Text()
        allure.attach("", "实际结果:"+siji)
        yuqi=data["yuqi"]
        return siji==yuqi


    def service_login_002(self,data):
        # 业务步骤
        # UI1的业务步骤
        self.page_index.openUrl()
        self.page_index.click_Login()

        # UI2的业务步骤
        self.page_login.input_zanhao(data["zanhao"])
        self.page_login.input_pwd(data["pwd"])

        self.page_login.click_login()


        # UI3的业务步骤
        siji=self.page_login.getTipsText()
        yuqi=data["yuqi"]
        return yuqi in siji


    def service_login_003(self,data):
        # 业务步骤
        # UI1的业务步骤
        self.page_index.openUrl()
        self.page_index.click_Login()

        # UI2的业务步骤
        self.page_login.input_zanhao(data["zanhao"])
        self.page_login.input_pwd(data["pwd"])

        self.page_login.click_login()

        # UI3的业务步骤
        siji=self.page_login.getZanhaoClass()
        yuqi=data["yuqi"]
        return yuqi in siji




